#ifndef LAYER_H_INCLUDED
#define LAYER_H_INCLUDED

#include <string>
#include <bitset>
#include <vector>
#include <iostream>
using namespace std;

typedef struct bit {
	char value : 1;
} bit;

class Util {
public:
	static vector<bit> Encode(string s) {
		int len = s.length() * 8;
		vector<bit> x(len);
		int idx = 0;
		for (auto item : s) {
			for (int i = 0; i < 8; i++) {
				int y = item & (1 << i);
				x[idx++].value = y == 0 ? 0 : 1;
			}
		}
		return x;
	};
	static string Decode(vector<bit> b) {
		string str = "";
		unsigned int idx = 0;
		while (idx < b.size()) {
			unsigned char ch = 0;
			for (int i = 0; i < 8; ++i) {
				if (b[idx++].value == 0) {
					continue;
				}
				ch |= (1 << i);
			}
			str.push_back(ch);
		}
		return str;
	};
};

class Layer {
public:
	virtual void Exec(string s) = 0;
	virtual vector<bit> Send() = 0;
	virtual void Recv(vector<bit> data) = 0;	
	virtual void SayHello() {}

};

#endif